package com.rui.shangXueTang.tree;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : ArrayBinaryTree
 * @createTime : [2022/2/17 15:33]
 * @description : [数组存储顺序二叉树]
 */

public class ArrayBinaryTree {

    private int[] arrays;

    public ArrayBinaryTree(int[] arrays) {
        this.arrays = arrays;
    }

    /**
     * 前序遍历存储顺序二叉树
     */
    public void preSelect(int index){
        if(this.arrays == null || arrays.length == 0){
            System.out.println("存储的数组为空");
            return;
        }

        //向左递归
        if((index * 2 + 1) < arrays.length){
            preSelect(index * 2 + 1);
        }

        //向右递归
        if((index * 2 + 2) < arrays.length){
            preSelect(index * 2 + 2);
        }
    }
}
